package thread;

import java.util.*;

/**
 * @description: TODO
 * @author yumo
 * @version: 1.0
 * @date 2025/3/18 9:17
 */
public class SyncApiDemo2{
    public static void main(String[] args) {
//        List<Integer> c= Collections.synchronizedList(new ArrayList<>());//List<Integer>c=new ArrayList<>();
        Set<Integer>c=Collections.synchronizedSet(new HashSet<>());//Set<Integer> c=new HashSet<>();
        Thread t1=new Thread(){
            public void run(){
                for (int i=0;i<1000;i++){
                    c.add(i);
                }
            }
        };
        Thread t2=new Thread(){
            public  void run (){
                for (int i=1000;i<2000;i++){
                    c.add(i);
                }
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(c.size());
    }
}
